<template>
  <div style="display: flex">
    <Card title="填写分类信息明细" dis-hover icon="md-document" style="flex: 1">
      <Form ref="FormData" :model="FormData" :label-width="140">
        <Row>
          <Col span="18" offset="3">
            <FormItem label="商品品类：">
              <span>{{ FormData.categoryType }}</span>
            </FormItem>
          </Col>
          <Col span="18" offset="3">
            <FormItem label="分类名称：">
              <span>{{ FormData.categoryName }}</span>
            </FormItem>
          </Col>
          <Col span="18" offset="3">
            <FormItem label="分类编码：">
              <span>{{ FormData.categoryNo }}</span>
            </FormItem>
          </Col>
          <Col span="18" offset="3">
            <FormItem label="位置：">
              <span>{{ FormData.position }}</span>
            </FormItem>
          </Col>
          <Col span="18" offset="3">
            <FormItem label="是否启用：">
              <RadioGroup v-model="FormData.state">
                <Radio label="1" disabled>启用</Radio>
                <Radio label="2" disabled>不启用</Radio>
              </RadioGroup>
            </FormItem>
          </Col>
          <Col span="18" offset="3">
            <FormItem label="描述：">
              <span>{{ FormData.categoryNote }}</span>
            </FormItem>
          </Col>
          <Col v-show="multipledata" span="18" offset="3">
            <Row type="flex">
              <FormItem label="限制类商品：">
                <RadioGroup v-model="FormData.categoryProductType">
                  <Radio label="1" disabled>危险品</Radio>
                  <Radio label="2" disabled>管制刀具</Radio>
                  <Radio label="3" disabled>非限制</Radio>
                </RadioGroup>
              </FormItem>
              <FormItem label="危化品等级：">
                <Select
                  v-model="FormData.dangerousOrder"
                  disabled
                  filterable
                  style="width: 200px"
                >
                  <Option
                    v-for="item in HCSList"
                    :value="item.value"
                    :key="item.value"
                    >{{ item.label }}
                  </Option>
                </Select>
              </FormItem>
            </Row>
            <Row>
              <FormItem label="关联商品模板：">
                <span>{{ FormData.productTemplateNames }}</span>
              </FormItem>
            </Row>
            <Row>
              <FormItem label="关联品牌：">
                <span>{{ FormData.brandNames }}</span>
                <BasicTable
                  :showSelectCol="false"
                  :showPagination="false"
                  :tableHeight="250"
                  :data-source="linkedBrandsTable.dataSource"
                  :columns="linkedBrandsTable.columns"
                ></BasicTable>
              </FormItem>
            </Row>
            <Row>
              <FormItem label="关联验收事项：">
                <span>{{ FormData.acceptItemNames }}</span>
              </FormItem>
            </Row>
            <Row>
              <FormItem label="关联归类名称：">
                <span>{{ FormData.classificationNames }}</span>
              </FormItem>
            </Row>
            <!-- <Row>
              <FormItem label="关联场景模版：">
                <span>{{ FormData.productSceneCategoryNames }}</span>
              </FormItem>
            </Row> -->
            <Row>
              <FormItem label="是否价格敏感：">
                <RadioGroup v-model="FormData.isPriceSensitive">
                  <Radio label="1" disabled>是</Radio>
                  <Radio label="2" disabled>否</Radio>
                </RadioGroup>
              </FormItem>
            </Row>
            <Row>
              <FormItem label="是否金属制品：">
                <RadioGroup v-model="FormData.isMetal">
                  <Radio label="1" disabled>是</Radio>
                  <Radio label="2" disabled>否</Radio>
                </RadioGroup>
              </FormItem>
            </Row>
            <Row>
              <FormItem label="是否重点：">
                <RadioGroup v-model="FormData.isKey">
                  <Radio label="1" disabled>是</Radio>
                  <Radio label="2" disabled>否</Radio>
                </RadioGroup>
              </FormItem>
            </Row>
            <!-- <Row>
                        <FormItem label="商品资质类型：">
                            <Button type="primary" @click="handleLink('qualiByCommodity')">设置</Button>
                        </FormItem>
                    </Row>
                    <Row>
                        <FormItem label="分类资质类型：">
                            <Button type="primary" @click="handleLink('qualiByClassify')">设置</Button>
                        </FormItem>
                    </Row> -->
            <Row>
              <FormItem label="批量订货额：">
                <span>{{ FormData.batchOrderPrice }} 元</span>
              </FormItem>
            </Row>
            <Row>
              <FormItem label="售价指导加价率：">
                <span>{{ FormData.guideAddRate }}</span>
              </FormItem>
            </Row>
            <Row>
              <FormItem label="成交最低加价率：">
                <span>{{ FormData.limitAddRate }}</span>
              </FormItem>
            </Row>
          </Col>
          <Col span="18" offset="3">
            <FormItem>
              <Button
                @click="handleReset()"
                class="ivu-ml-8"
                style="margin-right: 20px"
                >返回</Button
              >
              <!-- <Button v-if="FormData.reviewState!=='2'" @click="handleSubmit('0')" class="ivu-ml-8" style="margin-right: 20px;">审核不通过</Button>
                        <Button v-if="FormData.reviewState!=='2'" :loading="sLoading" type="primary" @click="handleSubmit('1')">审核通过</Button> -->
            </FormItem>
          </Col>
        </Row>
      </Form>
    </Card>
  </div>
</template>
<script>
import util from '@/libs/util';
import { ApiRequest } from '@api/basePage';
import BasicTable from '@/components/BasicTable';
import { isResponseSuccess } from '@/utils/bizUtils';
import { getEchoByOptions } from '@/utils/getUtils';
import { CATEGORY_TYPE_OPTIONS } from '@/constants/basics';

export default {
  components: { BasicTable },
  data () {
    return {
      linkedBrandsTable: { // 已关联品牌表格
        loading: false,
        dataSource: [], // 数据源
        columns: [
          { title: '品牌名称', key: 'brandName' },
          { title: '售价指导加价率', key: 'guideAddRate' },
          { title: '成交最低加价率', key: 'limitAddRate' },
        ], // 表格columns
      },
      linkAttribute: false,
      linkBrand: false,
      linkGather: false,
      linkCategory: false,
      linkScene: false,
      qualiByCommodity: false,
      qualiByClassify: false,
      ceshi: true,
      totalNum: 0,
      nowPage: 1,
      pageShow: 10, // 每页展示条数
      name: '',
      brandName: '',
      brandEnName: '',
      itemName: '',
      classificationName: '',
      taxCateName: '',
      taxCateNo: '',
      categoryName: '',
      parentName: '',
      linkAttributeValue: 'Name11',
      linkBrandValue: 'Name11',
      linkGatherValue: 'Name11',
      linkCategoryValue: 'Name11',
      linkSceneValue: 'Name11',
      linkAttributeData: [],
      linkBrandData: [],
      linkGatherData: [],
      linkCategoryData: [],
      linkSceneData: [],
      multipledata: false,
      isRootCategory: false,
      showRight: false,
      showCategory: true,
      HCSList: [
        {
          value: '1',
          label: '一级'
        },
        {
          value: '2',
          label: '二级'
        },
        {
          value: '3',
          label: '三级'
        }
      ],
      util: util,
      dynamicData: {},
      pagePath: '', // 当前路由
      FormRules: {},
      FormData: {
        parentUuid: 'systemUuid',
        categoryType: '',
        categoryName: '',
        categoryNo: '',
        categoryNote: '',
        levelNum: '',
        position: 0,
        state: '',
        uuid: '',
        categoryProductType: '',
        dangerousOrder: '',
        isPriceSensitive: '',
        isMetal: '',
        isKey: '',
        batchOrderPrice: 0,
        templateUuids: [],
        productTemplateNames: '',
        brandNames: '',
        brandUuids: [],
        acceptItemNames: '',
        acceptItemUuids: [],
        classificationUuids: [],
        classificationNames: '',
        productSceneCategoryUuids: [],
        productSceneCategoryNames: '',
        reviewState: '',
        guideAddRate: '', // 售价指导加价率
        limitAddRate: '', // 成交最低加价率
      },
      templateUuids: [],
      templateNames: [],
      brandUuids: [],
      brandNames: [],
      acceptItemNames: [],
      acceptItemUuids: [],
      classificationUuids: [],
      classificationNames: [],
      productSceneCategoryUuids: [],
      productSceneCategoryNames: [],
      rootDate: [],
      sLoading: false,
      uuid: '',
      templateUuidList: [], // 模板批量处理的数据
      brandUuidList: [], // 品牌批量处理数据
      relUuidsList: [], // 归类批量处理数据
      scenecategoryUuidList: [], // 场景批量处理数据
      relateUuidsList: [] // 验收事项
    };
  },
  watch: {
    $route: function () {
      this.$nextTick(() => {
        this.$router.go(0);
      });
    }
  },
  created () {
    this.getConfigData();
  },
  mounted () {},
  methods: {
    // 获取已有品牌表格信息请求入参
    getParamsByRequestTableData () {
      const relBrandUuids = [...this.FormData.brandUuids];
      const data = {
        brandName: '',
        brandEnName: '',
        relBrandUuids,
        nowPage: 1,
        pageShow: 1000,
        sortName: '',
        sortType: '',
        aduitCategoryUuid: this.FormData.uuid
      }
      return data;
    },
    // 获取已有品牌表格信息
    async getBrandsInfoByExist () {
      const url = '/sysback/productbrand/productbrand/getBrandRelByCondition';
      const type = 'post';
      const data = this.getParamsByRequestTableData();
      try {
        this.linkedBrandsTable.loading = true;
        const res = await ApiRequest(url, type, data);
        this.linkedBrandsTable.loading = false;
        if (isResponseSuccess(res)) {
          this.linkedBrandsTable.dataSource = res.retData.results;
        }
      } catch (err) {
        this.linkedBrandsTable.loading = false;
      }
    },
    // 获取初始配置信息
    getConfigData () {
      this.pagePath = this.$route.path;
      let dynamicData = require('./configjs/categoryAdd').default;
      this.requestApi = dynamicData.requestApi; // 页面所需接口集合
      this.$set(this.$data, 'dynamicData', dynamicData);
      this.uuid = this.$route.query.uuid;
      this.initData();
    },
    // 初始化数的数据
    initData () {
      let data = {
        platCategoryUuid: this.uuid
      };
      // 创建分类
      ApiRequest(
        this.requestApi.getPlatCategoryByUuid.url,
        this.requestApi.getPlatCategoryByUuid.type,
        data,
        true
      ).then((res) => {
        if (res.retStatus === '1') {
          this.FormData.categoryType = getEchoByOptions(res.retData.categoryType, CATEGORY_TYPE_OPTIONS);
          this.FormData.categoryName = res.retData.categoryName;
          this.FormData.categoryNo = res.retData.categoryNo;
          this.FormData.categoryNote = res.retData.categoryNote;
          this.FormData.position = res.retData.position;
          this.FormData.state = res.retData.state;
          this.FormData.levelNum = res.retData.levelNum;
          if (res.retData.levelNum === '4') {
            this.multipledata = true;
          } else {
            this.multipledata = false;
          }
          this.FormData.uuid = res.retData.uuid;
          this.FormData.parentUuid = res.retData.parentUuid;
          this.FormData.categoryProductType = res.retData.categoryProductType;
          this.FormData.dangerousOrder = res.retData.dangerousOrder;
          this.FormData.isPriceSensitive = res.retData.isPriceSensitive;
          this.FormData.isMetal = res.retData.isMetal;
          this.FormData.isKey = res.retData.isKey;
          this.FormData.batchOrderPrice = res.retData.batchOrderPrice;
          this.FormData.templateUuids = res.retData.templateUuids;
          this.FormData.brandUuids = res.retData.brandUuids;
          this.FormData.acceptItemUuids = res.retData.acceptItemUuids;
          this.FormData.classificationUuids = res.retData.classificationUuids;
          this.FormData.productSceneCategoryUuids =
            res.retData.productSceneCategoryUuids;
          this.FormData.productTemplateNames = res.retData.productTemplateNames;
          this.FormData.brandNames = res.retData.brandNames;
          this.FormData.reviewState = res.retData.reviewState;
          this.FormData.acceptItemNames = res.retData.acceptItemNames;
          this.FormData.classificationNames = res.retData.classificationNames;
          this.FormData.productSceneCategoryNames =
            res.retData.productSceneCategoryNames;
          this.FormData.guideAddRate = res.retData.guideAddRate; // 售价指导加价率
          this.FormData.limitAddRate = res.retData.limitAddRate; // 成交最低加价率
          this.getBrandsInfoByExist();
        }
      });
    },
    // 审核
    handleSubmit (type) {
      let data = {
        uuid: this.uuid
      };
      if (type === '0') {
        this.sLoading = true;
        ApiRequest(
          this.requestApi.auditNoPass.url + '?uuids=' + this.uuid,
          this.requestApi.auditNoPass.type,
          data,
          false
        ).then((res) => {
          if (res.retStatus === '1') {
            this.$Message.success('操作成功');
            this.$router.go(-1);
          }
          this.sLoading = false;
        });
      } else {
        this.sLoading = true;
        ApiRequest(
          this.requestApi.auditPass.url + '?uuids=' + this.uuid,
          this.requestApi.auditPass.type,
          data,
          false
        ).then((res) => {
          if (res.retStatus === '1') {
            this.$Message.success('操作成功');
            this.$router.go(-1);
          }
          this.sLoading = false;
        });
      }
    },
    handleReset () {
      this.$router.go(-1);
    }
  }
};
</script>
<style lang="less" scoped>
.qw-kuang {
}
</style>
